<?php
namespace app\index\validate;
use app\index\model\White;
use think\Validate;

class White extends Validate
{
    protected $rule =   [
        'account'  => 'checkAccServerName',
        'ip_from'  => 'checkAccServerName',
        'ip_end'   => 'checkAccServerName',    
    ];
	
    // 自定义验证规则
    protected function checkAccServerName($value,$rule,$data)
    {
		$type = $data['type'];
		switch($type){
			case 'account':
				$res = White::where('account',$data['account'])
							->where('server', $data['server'])
							->find();
				break;
			case 'ip':
				$res = White::where('ip_from',$data['ip_from'])
							->where('ip_end', $data['ip_end'])
							->where('server', $data['server'])
							->find();
				break;
		}
        return $res ? '重复白名单' : true;
    }
}
?>